package com.awspaas.user.apps.cpq.controller;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class CPQ_GetParameterHtmlPage {

	public String getParameterHtmlPage(UserContext userContext, String MKBH,String bindId,String boName,String MKMC) {
		try {
			String  sql="select  a.PARMENTIER_NAME,a.PARMENTIER_NO,a.DW from  "
					+ "BO_EU_CPQ_MODULE_MSG_PRICE_PARAMETERS  a ,BO_EU_CPQ_MODULE_MSG m "
					+ "where  a.BINDID=m.BINDID and m.MKBM=? ";
			List<RowMap> maps=DBSql.getMaps(sql, new Object[] {MKBH});
			List<BO> bos=SDK.getBOAPI().query(boName).bindId(bindId).list();
			Map<String, String> parmentiers=new HashMap<String, String>();
			if(bos.size()>0) {
				for (BO rowMap : bos) {					
					String no=rowMap.getString("PARMENTIER_NO");
					String value=rowMap.getString("PARMENTIER_VALUE");
					parmentiers.put(no, value);
				}
				}
			JSONObject jsonData=new JSONObject();
					jsonData.put("title", MKMC+"模块计算单价参数填写单");
			JSONArray jsonArray=new JSONArray();
			if(maps.size()>0) {
				for (RowMap rowMap : maps) {
					JSONObject json=new JSONObject();
					String name=rowMap.getString("PARMENTIER_NAME");
					String no=rowMap.getString("PARMENTIER_NO");
					String dw=rowMap.getString("DW");
					json.put("name", name);
					json.put("bh", no);
					json.put("dw", dw);
					if(parmentiers.containsKey(no)) {
						json.put("data", parmentiers.get(no));
					}else {
						json.put("data", "");
					}
					jsonArray.add(json);
					
				}
				}
			jsonData.put("dataList", jsonArray);
			System.out.println(jsonData.toJSONString());
			return jsonData.toJSONString();
		} catch (Exception e) {
			throw  e;
		}
		
	}

}
